
import axios from '../lib/axios.js';
//基准地址
axios.defaults.baseURL = 'http://localhost:9000';
let ajax = axios;
//验证用户是否登录
async function isLogin() {
    //获取 id 与 token
    let token = localStorage.getItem('token');
    let id = localStorage.getItem('uid');
    //用于检查变量id和token是否存在，如果不存在则status的值为0，未登录
    if (!id || !token) return {status: 0, message: '未登录'};
    //请求用户信息
    let {data: {code, user}} = await ajax.get('/users/info', {params: {id}, headers: {authorization: token}});
    if (code != 1) return {status: 0, message: '未登录'};
    //返回用户信息与 token
    return {status: 1, message: '已登录', user, token};
}
//导出
export {ajax, isLogin};